package org.shj.antlr.parser;

import org.antlr.v4.runtime.tree.ParseTree;

import java.util.List;

/**
 * @author Shen Huang Jian
 * @date 2020-12-01 14:48
 */
public class MathEmitter extends MathBaseListener  {

    @Override
    public void enterProg(MathParser.ProgContext ctx) {
        System.out.println("=============");
        System.out.println(ctx.getText());
        System.out.println(ctx.getStart().getText());

        System.out.println(ctx.getStop().getText());

        List<ParseTree> child = ctx.children;

        for(ParseTree parseTree : child){
            //parseTree.
            System.out.println(parseTree.getText());
        }

        List<MathParser.StatContext> statContexts = ctx.stat();
        for(MathParser.StatContext sc : statContexts){
            print(sc);
        }

    }

    private void print(MathParser.StatContext sc){
        System.out.println("====== " + sc.getText());

    }

}
